package com.ryan.chat.util;

import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.http.Method;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

/**
 * @author 308039
 * @version 1.0.0
 * @type RequestUtil.java
 * @description
 * @date 2024/10/22 16:50
 */
public class RequestUtil {

  public static String requestSend(Method method, String url, Map<String, String> headers,
                                   Map<String, Object> formMap, String body) {

//    Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.30.6.49", 9090));

//    HttpRequest httpRequest = HttpUtil.createRequest(method, url).setProxy(proxy)
//            .addHeaders(Optional.ofNullable(headers).orElse(new HashMap<>()));

    HttpRequest httpRequest = HttpUtil.createRequest(method, url)
            .addHeaders(Optional.ofNullable(headers).orElse(new HashMap<>(0)));

    switch (method.name()) {
      case "POST":
        httpRequest.form(Optional.ofNullable(formMap).orElse(new HashMap<>(0)));

        break;
      case "GET":
        httpRequest.body(body);
        break;
      case "DELETE":

        break;
      default:
    }
    HttpResponse execute = httpRequest.execute();
    return execute.body();
  }

}
